﻿using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Dusts
{
    public class AcidSmoke : ModDust
    {
        public override void OnSpawn(Dust dust)
        {
            dust.frame = new Rectangle(0, Main.rand.Next(3) * 36, 34, 36);
            dust.rotation = Main.rand.NextFloat(6.28f);
            dust.noGravity = true;
            dust.scale = Main.rand.NextFloat(0.2f, 0.4f);
        }
        public override Color? GetAlpha(Dust dust, Color lightColor)
        {
            Color color;
            color = new(218, 250, 156);
            if (dust.alpha < 160)
            {
                color = Color.Lerp(new Color(35, 186, 63), new Color(160, 235, 92), dust.alpha / 160f);
            }
            return new Color?(color * ((255f - dust.alpha) / 255f));
        }
        public override bool Update(Dust dust)
        {
            dust.position += dust.velocity;
            dust.alpha += 12;
            dust.scale += MathHelper.Lerp(0.003f, 0.008f, dust.alpha / 255f);
            dust.velocity *= MathHelper.Lerp(0.85f, 0.75f, dust.alpha / 175f);
            dust.rotation += MathHelper.Lerp(0.01f, 0.001f, dust.alpha / 175f) * (dust.dustIndex % 2 == 0 ? -1 : 1);
            if (dust.alpha >= 255)
            {
                dust.active = false;
            }
            return false;
        }
    }
}
